package com.gxc.controller;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * post请求获取参数.
 *
 * @author 宫新程
 * @since 2018/12/11 2:03 PM
 */
@Controller
public class PostController {

  @RequestMapping("/page/post")
  public String postPage() {
    return "post";
  }

  /** post 请求测试获取参数. */
  @PostMapping("/postMethod")
  @ResponseBody
  public String postMethod(HttpServletRequest request) {
    StringBuilder sb = new StringBuilder();
    Map<String, String[]> parameterMap = request.getParameterMap();
    parameterMap.forEach((k, v) -> sb.append(k + "：" + request.getParameter(k) + "<br/>"));
    sb.append("requestMethod：" + request.getMethod() + "<br/>");
    return sb.toString();
  }
}
